package com.ctshk.rpc.localfun.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.localfun.dto.LocalFunOfflineSelCustomDTO;
import com.ctshk.rpc.localfun.entity.LocalFunProductCostStrategyVaildDate;
import com.ctshk.rpc.localfun.entity.LocalFunProductSaleStrategyVaildDate;
import com.ctshk.rpc.localfun.req.LocalFunProductCostReq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description
 * @Author wansi <gaylen15527491065@yeah.net>
 * @Date 2021/3/23
 */
public interface LocalFunProductCostStrategyVaildDateMapper extends BaseMapper<LocalFunProductCostStrategyVaildDate> {

    @Select("<script>"+"select t1.strategy_id increaseStrategyId,t2.visable_type visableType,t3.adjust_type adjustType,t3.relation_id relationId,t3.amount,t3.percent from t_local_fun_product_sale_strategy_vaild_date t1 " +
            "LEFT JOIN t_local_fun_product_channel_offline t2 on t1.strategy_id=t2.strategy_id  LEFT JOIN t_local_fun_product_channel_offline_self_custom t3 on t2.id=t3.offline_id where " +
            "t1.time_begin &lt;=#{localFunProductCostReq.queryDate} and t1.time_end &gt;=#{localFunProductCostReq.queryDate}\n" +
            "AND t2.channel_type=1 and t1.product_id=#{localFunProductCostReq.productId}" + "</script>")
    List<LocalFunOfflineSelCustomDTO> getProductSaleList(@Param("localFunProductCostReq") LocalFunProductCostReq localFunProductCostReq);

    @Select("<script>"+"select min(time_begin) timeBegin ,max(time_end) timeEnd from t_local_fun_product_cost_strategy_vaild_date where product_id=#{id}" + "</script>")
    LocalFunProductCostStrategyVaildDate selectValidteTime(Long id);
}
